
********************************************************************************
* Create a dataset with DESO 2017 (neighbourhood where individuals live)
********************************************************************************

* Retrieve table "DESO_Bostad17" from SQL database
odbc load, exec("select * from DESO_Bostad17")dsn("P0846") clear
duplicates drop
duplicates tag Lopnr_personnr, gen(dupli_personID)
tab dupli_personID
sort dupli_personID Lopnr_personnr
duplicates drop Lopnr_personnr, force
rename Lopnr_personnr PersonId
drop dupli_personID
save Data/data_DESO_Bostad_2017, replace

* Retrieve table "DESO_Bostad16" from SQL database
odbc load, exec("select * from DESO_Bostad16")dsn("P0846") clear
duplicates drop
duplicates tag Lopnr_personnr, gen(dupli_personID)
tab dupli_personID
sort dupli_personID Lopnr_personnr
duplicates drop Lopnr_personnr, force
rename Lopnr_personnr PersonId
save Data/data_DESO_Bostad_2016, replace

* Retrieve table "DESO_Bostad15" from SQL database
odbc load, exec("select * from DESO_Bostad15")dsn("P0846") clear
duplicates drop
duplicates tag Lopnr_personnr, gen(dupli_personID)
tab dupli_personID
sort dupli_personID Lopnr_personnr
duplicates drop Lopnr_personnr, force
rename Lopnr_personnr PersonId
save Data/data_DESO_Bostad_2015, replace

* Retrieve table "DESO_Bostad14" from SQL database
odbc load, exec("select * from DESO_Bostad14")dsn("P0846") clear
duplicates drop
duplicates tag Lopnr_personnr, gen(dupli_personID)
tab dupli_personID
sort dupli_personID Lopnr_personnr
duplicates drop Lopnr_personnr, force
rename Lopnr_personnr PersonId
save Data/data_DESO_Bostad_2014, replace

* Retrieve table "DESO_Bostad13" from SQL database
odbc load, exec("select * from DESO_Bostad13")dsn("P0846") clear
duplicates drop
duplicates tag Lopnr_personnr, gen(dupli_personID)
tab dupli_personID
sort dupli_personID Lopnr_personnr
duplicates drop Lopnr_personnr, force
rename Lopnr_personnr PersonId
save Data/data_DESO_Bostad_2013, replace

* Retrieve table "DESO_Bostad18" from SQL database
odbc load, exec("select * from DESO_Bostad18")dsn("P0846") clear
duplicates drop
duplicates tag Lopnr_personnr, gen(dupli_personID)
tab dupli_personID
sort dupli_personID Lopnr_personnr
duplicates drop Lopnr_personnr, force
rename Lopnr_personnr PersonId
save Data/data_DESO_Bostad_2018, replace

